﻿/*
 * Created by SharpDevelop.
 * User: IEscarro
 * Date: 9/7/2009
 * Time: 6:33 PM
 * 
 * To change this template use Tools | Options | Coding | Edit Standard Headers.
 */

using System;
using NHibernate;
using System.Collections.Generic;
using System.Data;
using Buaya.Model.Dao.Interface;

namespace Buaya.Model.Dao.NHibernate
{
	/// <summary>
	/// Description of NHibernateModuleDao.
	/// </summary>
	public class NHibernateModuleDao : IModuleDao
	{
		public NHibernateModuleDao()
		{
		}
		
		public void SaveOrUpdate(Module module)
		{
			ISession session = NHibernateHelper.OpenSession();
			session.SaveOrUpdate(module);
			session.Flush();
		}
		
		public void Delete(Module module)
		{
			ISession session = NHibernateHelper.OpenSession();
			session.Delete(module);
			session.Flush();
		}
		
		public Module ReadByPk(int id)
		{
			return NHibernateHelper.OpenSession().Load<Module>(id);
		}
		
		public IList<Module> FindAll()
		{
//			return NHibernateHelper.OpenSession().CreateCriteria(typeof(Module)).List<Module>();
			return NHibernateHelper.OpenSession().CreateQuery("from Module order by PlacementOrder asc").List<Module>();
		}
	}
}
